$(document).ready(function(){
	$('#fileuploader').swfupload({
		upload_url: "upload.php",
		file_size_limit : "500MB",
		file_types : "*.*",
		file_types_description : "All Files",
		file_upload_limit : "0",
		flash_url : "/swf/uploader.swf",
		button_image_url : '/img/XPButtonUploadText_61x22.png',
		button_width : 61,
		button_height : 22,
		button_placeholder : $('#charge')[0],
		debug: true
	})
		.bind('swfuploadLoaded', function(event) {			
		})
		.bind('fileQueued', function(event, file) {
			var html = '<tr id = "'	+ file.id + '"><td class = "name"><div>' + file.name + '(' + Math.round(file.size / 1024) + 'KB)</div></td>' + 
				'<td class = "progress"><div class = "file">&nbsp;</div><div class = "bar-wrap"><span class = "bar"></span></div></tr>';
			$('#filelist').append(html);
			$(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message) {
			var html = '<td class = "red-back red-border" colspan = "2">' + file.name + ' не удалось загрузить по причине:<br />' + 
			'<span class = "b">' + message + '</span></td>';
			$('#filelist').append(html);
		})
		.bind('uploadStart', function(event, file) {
			$('#' + file.id + ' .file').text('0%');
		})
		.bind('uploadProgress', function(event, file, bytesLoaded) {
			var text = Math.round(bytesLoaded / file.size * 100) + '%';
			$('#' + file.id + ' .file').text(text);
			$('#' + file.id + ' .bar').css('width', text);
		})
		.bind('uploadSuccess', function(event, file, serverData) {
			var html = '<td class = "green-back green-border" colspan = "2">' + file.name + ' успешно загружен</td>';
			$('#' + file.id).html(html);
		})
		.bind('uploadComplete', function(event, file) {
			//
			$(this).swfupload('startUpload');
		})
		.bind('uploadError', function(event, file, errorCode, message) {
			var html = '<td class = "red-back red-border" colspan = "2">' + file.name + ' не удалось загрузить по причине:<br />' + 
				'<span class = "b">' + message + '</span></td>';
			$('#' + file.id).html(html);
		});	
});	